package com.hsc.yalebao.newui;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.google.gson.Gson;
import com.hsc.yalebao.base.ActivityStack;
import com.hsc.yalebao.base.BaseFragment;
import com.hsc.yalebao.base.CustomApplication;
import com.hsc.yalebao.base.MainActivity;
import com.hsc.yalebao.http.AppConstants;
import com.hsc.yalebao.http.RequestNet;
import com.hsc.yalebao.model.AvdBaseModel;
import com.hsc.yalebao.model.AvdModel;
import com.hsc.yalebao.model.NumberModel;
import com.hsc.yalebao.model.RoomListBaseBean;
import com.hsc.yalebao.model.RoomListBean;
import com.hsc.yalebao.tabMine.WanFaActivity;
import com.hsc.yalebao.tools.UiUtil;
import com.hsc.yalebao.weight.LogUtils;
import com.zhy.http.okhttp.callback.StringCallback;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Timer;
import java.util.TimerTask;
import okhttp3.Call;

@SuppressLint({"NewApi"})
public class NewIndexFragment extends BaseFragment
  implements View.OnClickListener
{
  public static NewIndexFragment fragment;
  private String TAG = "IndexFragment";
  String canadaLotteryId;
  String canadaRoomId;
  private View contentView;
  private int currentItem = 0;
  private ArrayList<ImageView> dot_view;
  private Handler handler = new Handler()
  {
    public void handleMessage(Message paramAnonymousMessage)
    {
      if ((NewIndexFragment.this.viewPager != null) && (NewIndexFragment.this.pic_ids != null) && (NewIndexFragment.this.pic_ids.size() != 0))
      {
        NewIndexFragment.this.currentItem = ((1 + NewIndexFragment.this.viewPager.getCurrentItem()) % NewIndexFragment.this.pic_ids.size());
        NewIndexFragment.this.viewPager.setCurrentItem(NewIndexFragment.this.currentItem);
      }
      LogUtils.i(NewIndexFragment.this.TAG, "currentItem:" + NewIndexFragment.this.currentItem);
    }
  };
  private ImageView img;
  private ImageView img_scroll_left;
  private ImageView img_scroll_right;
  private ImageView img_wanfa_canada;
  private ImageView img_wanfa_paking;
  private boolean isRunning = true;
  private LinearLayout layout_dots;
  private RelativeLayout lin_canda_28;
  private RelativeLayout lin_paking_28;
  private LinearLayout lin_rooms;
  private LinearLayout mOneLayout;
  private LinearLayout mTwoLayout;
  private NewViewPagerAdapter pagerAdapter;
  String pakingLotteryId;
  String pakingRoomId;
  public ArrayList<AvdBaseModel> pic_ids;
  private int screenHeight = 0;
  private int screenWidth = 0;
  private Timer timer = new Timer();
  private AdvTimerTask timerTask;
  private TextView tv_earn_money_index;
  private TextView tv_register_people_count;
  private TextView tv_zhuanqian_percent;
  private ViewPager viewPager;
  private WindowManager windowManager;

  private void getBanners()
  {
    HashMap localHashMap = new HashMap();
    localHashMap.put("Type", "0");
    localHashMap.put("num", "4");
    RequestNet.get(getActivity(), AppConstants.URL_GET_AD_LIST, localHashMap, new StringCallback()
    {
      public void onError(Call paramAnonymousCall, Exception paramAnonymousException)
      {
        LogUtils.e(NewIndexFragment.this.TAG, "获取失败,获取banner:" + paramAnonymousException);
      }

      public void onResponse(String paramAnonymousString)
      {
        LogUtils.d(NewIndexFragment.this.TAG, "result:" + paramAnonymousString);
        Gson localGson = new Gson();
        try
        {
          localAvdModel = (AvdModel)localGson.fromJson(paramAnonymousString, AvdModel.class);
          if (localAvdModel == null)
          {
            LogUtils.e(NewIndexFragment.this.TAG, "获取失败");
            return;
          }
        }
        catch (Exception localException)
        {
          AvdModel localAvdModel;
          do
          {
            while (true)
            {
              localException.printStackTrace();
              localAvdModel = null;
            }
            if (localAvdModel.getFlag() == -4)
            {
              ActivityStack.getInstance().backToMain(MainActivity.class, NewIndexFragment.this.getActivity());
              return;
            }
            if (localAvdModel.getFlag() == 0)
            {
              UiUtil.showToast(NewIndexFragment.this.getActivity(), localAvdModel.getMsg());
              return;
            }
            if (localAvdModel.getFlag() == -2)
            {
              MainActivity.mainActivity.showOffLineDialog();
              return;
            }
            if (localAvdModel.getFlag() == -3)
            {
              MainActivity.mainActivity.showFengjinDialog();
              return;
            }
          }
          while (localAvdModel.getFlag() != 1);
          NewIndexFragment.this.pic_ids = localAvdModel.getResult();
          NewIndexFragment.this.initDotsAndMakeStart();
        }
      }
    });
  }

  private void getBanners2()
  {
    initDotsAndMakeStart();
  }

  private void getNumberInfo()
  {
    HashMap localHashMap = new HashMap();
    LogUtils.i(this.TAG, "getNumberInfo()-Url:" + AppConstants.URL_GET_CONFIG);
    RequestNet.get(getActivity(), AppConstants.URL_GET_CONFIG, localHashMap, new StringCallback()
    {
      public void onError(Call paramAnonymousCall, Exception paramAnonymousException)
      {
        Log.e(NewIndexFragment.this.TAG, "获取失败,获取首页注册人数 赚钱率:" + paramAnonymousException);
      }

      public void onResponse(String paramAnonymousString)
      {
        LogUtils.d(NewIndexFragment.this.TAG, "result:" + paramAnonymousString);
        if ((paramAnonymousString == null) || ("".equals(paramAnonymousString)))
          return;
        Gson localGson = new Gson();
        try
        {
          localNumberModel = (NumberModel)localGson.fromJson(paramAnonymousString, NumberModel.class);
          if (localNumberModel == null)
          {
            LogUtils.e(NewIndexFragment.this.TAG, "获取失败");
            return;
          }
        }
        catch (Exception localException)
        {
          NumberModel localNumberModel;
          while (true)
          {
            localException.printStackTrace();
            localNumberModel = null;
          }
          if (localNumberModel.getFlag() == -4)
          {
            ActivityStack.getInstance().backToMain(MainActivity.class, NewIndexFragment.this.getActivity());
            return;
          }
          if (localNumberModel.getFlag() == 1)
          {
            int i = localNumberModel.getReg_num();
            double d1 = localNumberModel.getEarn_total();
            double d2 = localNumberModel.getEarn_rate();
            NewIndexFragment.this.tv_earn_money_index = ((TextView)NewIndexFragment.this.contentView.findViewById(2131100101));
            NewIndexFragment.this.tv_register_people_count = ((TextView)NewIndexFragment.this.contentView.findViewById(2131100102));
            NewIndexFragment.this.tv_zhuanqian_percent = ((TextView)NewIndexFragment.this.contentView.findViewById(2131100103));
            NewIndexFragment.this.tv_earn_money_index.setText((int)d1 + "元宝");
            NewIndexFragment.this.tv_register_people_count.setText(i + "人");
            NewIndexFragment.this.tv_zhuanqian_percent.setText((int)(100.0D * d2));
            return;
          }
          if (localNumberModel.getFlag() == -2)
          {
            MainActivity.mainActivity.showOffLineDialog();
            return;
          }
          UiUtil.showToast(NewIndexFragment.this.getActivity(), localNumberModel.getMsg());
        }
      }
    });
  }

  private void getParent0RoomListInfo()
  {
    HashMap localHashMap = new HashMap();
    localHashMap.put("parentID", "0");
    localHashMap.put("lottery_id", "0");
    LogUtils.i(this.TAG, "getParent0RoomListInfo()-Url:" + AppConstants.URL_GET_ROOMBYPARENTID);
    RequestNet.get(getActivity(), AppConstants.URL_GET_ROOMBYPARENTID, localHashMap, new StringCallback()
    {
      public void onError(Call paramAnonymousCall, Exception paramAnonymousException)
      {
        LogUtils.e(NewIndexFragment.this.TAG, "获取失败,getParent1RoomListInfo-result:" + paramAnonymousException);
      }

      public void onResponse(String paramAnonymousString)
      {
        LogUtils.d(NewIndexFragment.this.TAG, "result:" + paramAnonymousString);
        Gson localGson = new Gson();
        try
        {
          localRoomListBean = (RoomListBean)localGson.fromJson(paramAnonymousString, RoomListBean.class);
          if (localRoomListBean == null)
          {
            LogUtils.e(NewIndexFragment.this.TAG, "获取失败");
            return;
          }
        }
        catch (Exception localException)
        {
          RoomListBean localRoomListBean;
          ArrayList localArrayList;
          do
          {
            while (true)
            {
              localException.printStackTrace();
              localRoomListBean = null;
            }
            if (localRoomListBean.getFlag() == -4)
            {
              ActivityStack.getInstance().backToMain(MainActivity.class, NewIndexFragment.this.getActivity());
              return;
            }
            if (localRoomListBean.getFlag() != 1)
              break;
            localArrayList = localRoomListBean.getResult();
          }
          while ((localArrayList == null) || (localArrayList.size() <= 0));
          for (int i = 0; i < localArrayList.size(); i++)
          {
            RoomListBaseBean localRoomListBaseBean = (RoomListBaseBean)localArrayList.get(i);
            if (localRoomListBaseBean != null)
            {
              String str = localRoomListBaseBean.getTitle();
              localRoomListBaseBean.getOnline_num();
              int j = localRoomListBaseBean.getId();
              int k = localRoomListBaseBean.getLottery_id();
              if ("北京快乐28".equals(str))
              {
                NewIndexFragment.this.pakingRoomId = j;
                NewIndexFragment.this.pakingLotteryId = k;
              }
              if ("加拿大28".equals(str))
              {
                NewIndexFragment.this.canadaRoomId = j;
                NewIndexFragment.this.canadaLotteryId = k;
              }
            }
          }
          if (localRoomListBean.getFlag() == -2)
          {
            MainActivity.mainActivity.showOffLineDialog();
            return;
          }
          UiUtil.showToast(NewIndexFragment.this.getActivity(), localRoomListBean.getMsg());
        }
      }
    });
  }

  private void init()
  {
    this.mOneLayout = ((LinearLayout)this.contentView.findViewById(2131100320));
    this.mTwoLayout = ((LinearLayout)this.contentView.findViewById(2131100321));
    this.mOneLayout.setOnClickListener(this);
    this.mTwoLayout.setOnClickListener(this);
    this.pic_ids = new ArrayList();
    this.dot_view = new ArrayList();
    this.pic_ids.clear();
    int[] arrayOfInt = { 2130837517, 2130837518, 2130837519, 2130837520 };
    for (int i = 0; ; i++)
    {
      if (i >= arrayOfInt.length)
      {
        this.layout_dots = ((LinearLayout)this.contentView.findViewById(2131100033));
        this.viewPager = ((ViewPager)this.contentView.findViewById(2131100090));
        if (this.pagerAdapter == null)
          this.pagerAdapter = new NewViewPagerAdapter(this.pic_ids, getActivity());
        this.viewPager.setAdapter(this.pagerAdapter);
        this.viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener()
        {
          int oldPosition = 0;

          public void onPageScrollStateChanged(int paramAnonymousInt)
          {
            LogUtils.d("onPageScrollStateChanged", "arg0:" + paramAnonymousInt);
          }

          public void onPageScrolled(int paramAnonymousInt1, float paramAnonymousFloat, int paramAnonymousInt2)
          {
          }

          public void onPageSelected(int paramAnonymousInt)
          {
            if (NewIndexFragment.this.isRunning)
            {
              ((ImageView)NewIndexFragment.this.dot_view.get(this.oldPosition)).setImageResource(2130838124);
              ((ImageView)NewIndexFragment.this.dot_view.get(paramAnonymousInt)).setImageResource(2130838125);
              this.oldPosition = paramAnonymousInt;
            }
          }
        });
        this.tv_earn_money_index = ((TextView)this.contentView.findViewById(2131099960));
        this.tv_register_people_count = ((TextView)this.contentView.findViewById(2131100102));
        this.tv_zhuanqian_percent = ((TextView)this.contentView.findViewById(2131100103));
        this.lin_paking_28 = ((RelativeLayout)this.contentView.findViewById(2131100104));
        this.lin_canda_28 = ((RelativeLayout)this.contentView.findViewById(2131100107));
        this.img_scroll_left = ((ImageView)this.contentView.findViewById(2131100110));
        this.img_scroll_left.setVisibility(8);
        this.img_scroll_right = ((ImageView)this.contentView.findViewById(2131100111));
        this.img_scroll_right.setVisibility(8);
        this.img_wanfa_paking = ((ImageView)this.contentView.findViewById(2131100106));
        this.img_wanfa_canada = ((ImageView)this.contentView.findViewById(2131100109));
        ViewGroup.LayoutParams localLayoutParams = this.img_wanfa_paking.getLayoutParams();
        localLayoutParams.width = (this.screenWidth / 2);
        this.img_wanfa_paking.setLayoutParams(localLayoutParams);
        this.img_wanfa_canada.setLayoutParams(localLayoutParams);
        this.lin_paking_28.setOnClickListener(this);
        this.lin_canda_28.setOnClickListener(this);
        this.img_scroll_left.setOnClickListener(this);
        this.img_scroll_right.setOnClickListener(this);
        this.img_wanfa_paking.setOnClickListener(this);
        this.img_wanfa_canada.setOnClickListener(this);
        return;
      }
      AvdBaseModel localAvdBaseModel = new AvdBaseModel();
      localAvdBaseModel.setId(i);
      this.pic_ids.add(localAvdBaseModel);
    }
  }

  private void initDotsAndMakeStart()
  {
    if ((this.pic_ids != null) && (this.pic_ids.size() > 0))
    {
      if (this.timerTask != null)
      {
        this.timerTask.cancel();
        this.timerTask = null;
      }
      if (this.layout_dots != null)
        this.layout_dots.removeAllViews();
      if ((this.dot_view != null) && (this.dot_view.size() != 0))
        this.dot_view.clear();
    }
    for (int i = 0; ; i++)
    {
      if (i >= this.pic_ids.size())
      {
        this.pagerAdapter.notifyDataSetChanged();
        this.timerTask = new AdvTimerTask();
        this.timer.scheduleAtFixedRate(this.timerTask, 0L, 4000L);
        return;
      }
      ImageView localImageView = new ImageView(getActivity());
      localImageView.setImageDrawable(getActivity().getResources().getDrawable(2130838124));
      this.dot_view.add(localImageView);
      this.layout_dots.addView(localImageView);
    }
  }

  public void getDatasFromServer()
  {
    getNumberInfo();
    getBanners();
  }

  public void onActivityCreated(Bundle paramBundle)
  {
    super.onActivityCreated(paramBundle);
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    default:
      return;
    case 2131100320:
      Intent localIntent6 = new Intent(getActivity(), NewDetailMessageActivity.class);
      localIntent6.putExtra("type", "1");
      startActivity(localIntent6);
      return;
    case 2131100321:
      Intent localIntent5 = new Intent(getActivity(), NewDetailMessageActivity.class);
      localIntent5.putExtra("type", "2");
      startActivity(localIntent5);
      return;
    case 2131100104:
      Intent localIntent4 = new Intent(getActivity(), WanFaActivity.class);
      localIntent4.putExtra("instructionType", "1");
      startActivity(localIntent4);
      return;
    case 2131100107:
      Intent localIntent3 = new Intent(getActivity(), WanFaActivity.class);
      localIntent3.putExtra("instructionType", "2");
      startActivity(localIntent3);
      return;
    case 2131100106:
      Intent localIntent2 = new Intent(getActivity(), NewWanFaActivity.class);
      localIntent2.putExtra("type", "1");
      startActivity(localIntent2);
      return;
    case 2131100109:
    }
    Intent localIntent1 = new Intent(getActivity(), NewWanFaActivity.class);
    localIntent1.putExtra("type", "2");
    startActivity(localIntent1);
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    fragment = this;
  }

  public View onCreateView(LayoutInflater paramLayoutInflater, ViewGroup paramViewGroup, Bundle paramBundle)
  {
    this.contentView = paramLayoutInflater.inflate(2130903203, null);
    this.screenWidth = CustomApplication.app.displayMetrics.widthPixels;
    this.screenHeight = CustomApplication.app.displayMetrics.heightPixels;
    init();
    getBanners2();
    return this.contentView;
  }

  public void onDestroy()
  {
    super.onDestroy();
    this.isRunning = false;
    if (this.timer != null)
    {
      this.timer.cancel();
      this.timer = null;
    }
    if (this.timerTask != null)
    {
      this.timerTask.cancel();
      this.timerTask = null;
    }
  }

  public void onResume()
  {
    super.onResume();
    getDatasFromServer();
  }

  class AdvTimerTask extends TimerTask
  {
    AdvTimerTask()
    {
    }

    public void run()
    {
      NewIndexFragment.this.handler.sendEmptyMessage(0);
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.newui.NewIndexFragment
 * JD-Core Version:    0.6.2
 */